#include "linkfabric/TLV.hpp"
#include "linkfabric/Message.hpp"
#include "linkfabric/Crypto.hpp"
#include <cassert>
#include <iostream>

using namespace linkfabric;

void testTLV() {
    TLV tlv(0x01, {'H','i'});
    auto encoded = tlv.encode();
    size_t offset = 0;
    TLV decoded = TLV::decode(encoded, offset);
    assert(decoded.tag == 0x01);
    assert(decoded.value == std::vector<uint8_t>({'H','i'}));
    std::cout << "✅ TLV encode/decode passed\n";
}

void testMessage() {
    Message msg;
    msg.header = {1, 0x01, 0, 0, 42};
    msg.body = { TLV(0x01, {'A','I'}), TLV(0x02, {'C','o','p','i','l','o','t'}) };
    auto raw = msg.encode();
    Message decoded = Message::decode(raw);
    assert(decoded.header.channel_id == 42);
    assert(decoded.body.size() == 2);
    std::cout << "✅ Message encode/decode passed\n";
}

void testCrypto() {
    std::string key = "secret";
    std::vector<uint8_t> data = {'t','e','s','t'};
    auto encrypted = Crypto::encrypt(data, key);
    auto decrypted = Crypto::decrypt(encrypted, key);
    assert(decrypted == data);
    std::cout << "✅ AES encrypt/decrypt passed\n";
}

int main() {
    testTLV();
    testMessage();
    testCrypto();
    return 0;
}
